package net.expectx.pay.common.util;

import com.alibaba.fastjson.JSONObject;

import java.util.*;

/**
 * @author lijian
 */
public class ExpectXUtil {
    /**
     * 过滤语言
     * @param content
     * @param lanuage
     * @return
     */
    public static String filterLanguage(String content,String lanuage){

        try {
            JSONObject json=JSONObject.parseObject(content);
            return json.getString(lanuage);
        }catch (Exception e){
            return content;
        }
    }
    public static List<Long> toList(String val, String split){
        List<Long> longs=new ArrayList<>();
        String [] v=val.split(split);
        for (String s:v){
            longs.add(Long.valueOf(s));
        }
        return longs;
    }
    public static String putPairsSequenceAndTogether(Map<String, String> info) {
        List<Map.Entry<String, String>> infoIds = new ArrayList<Map.Entry<String, String>>(info.entrySet());
        Collections.sort(infoIds, new Comparator<Map.Entry<String, String>>() {
            @Override
            public int compare(Map.Entry<String, String> arg0, Map.Entry<String, String> arg1) {
                return (arg0.getKey()).compareTo(arg1.getKey());
            }
        });
        String ret = "";
        for (Map.Entry<String, String> entry : infoIds) {
            ret += entry.getKey();
            ret += "=";
            ret += entry.getValue();
            ret += "&";
        }
        ret = ret.substring(0, ret.length() - 1);
        return ret;
    }
}
